package com.bwie.mq;

import com.bwie.mapper.UserMapper;
import com.bwie.pojo.po.Customer;
import com.bwie.pojo.po.User;
import com.bwie.utils.SendMsgUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

public class MessageConsumer implements MessageListener {
    @Autowired
    public HttpServletRequest request;
    @Autowired
    public UserMapper userMapper;

    @Override
    public void onMessage(Message message) {
        byte[] body = message.getBody();
        Customer customer = (Customer) SerializationUtils.deserialize(body);
        User user = (User) request.getSession().getAttribute("user");
        if (user!=null){
        System.out.println("创始人"+user.getUserName()+ "要发送的信息"+customer);
            User login = userMapper.login(user.getUserName());
            SendMsgUtil.sendSms(login.getTel(),"2123");
        }

    }
}
